﻿using System;
using System.Web.UI.WebControls;
using Pharmacy.Settings.BusinessLayer;
using Pharmacy.Web.UI;
using Pharmacy.Data;
using Pharmacy.Entities;

public partial class Admin_ImportAdjust : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        FormUtil.RedirectAfterUpdate(GridView1, "ImportAdjust.aspx?page={0}");
        FormUtil.SetPageIndex(GridView1, "page");
        FormUtil.SetDefaultButton((Button)GridViewSearchPanel1.FindControl("cmdSearch"));
        //if (!IsPostBack)
        //    WhereClauseHiddenField.Value = GetWhereClause();
    }
    protected string GetWhereClause()
    {
        string WhereClause = "left(GrnId,1)='I'"; //lay gia tri dau tien cua prefix
        return WhereClause;
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string urlParams = string.Format("GrnId={0}", GridView1.SelectedDataKey.Values[0]);
        Response.Redirect("ImportAdjustEdit.aspx?" + urlParams, true);
    }
    protected void GrnDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {
        //Parameter where= GrnDataSource.Parameters["WhereClause"];
        if (String.IsNullOrEmpty(e.InputParameters["WhereClause"].ToString()))
            e.InputParameters["WhereClause"] = GetWhereClause();
        else
            e.InputParameters["WhereClause"] += " And " + GetWhereClause();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string grnID = e.CommandArgument.ToString().Trim();
        if (e.CommandName == "CustomDelete")
        {

            TList<Pharmacy.Entities.GrnDetails> objGrndetail = DataRepository.GrnDetailsProvider.GetByGrnId(grnID);
            if (objGrndetail.Count > 0)
            {
                Response.Write(@"<script language='javascript'>alert('Vui lòng xóa tất cả chi tiết.')</script>");

            }
            else
            {
                Pharmacy.Entities.Grn objGrn = new Pharmacy.Entities.Grn();
                objGrn.GrnId = grnID;
                DataRepository.GrnProvider.Delete(objGrn);
            }
            //  GridView1.DataBind();
        }
    }
}
